package cn.nawang.ebeim.api.controller;

import java.util.HashMap;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import cn.nawang.ebeim.api.domain.StorageFileToDo;
import cn.nawang.ebeim.api.service.StorageFileToDoService;
import cn.nawang.ebeim.api.utils.Constant;

/**
 * @ClassName: StorageFileToDoController
 * @Description: TODO
 * @author fanyb
 * @date Aug 26, 2015 2:59:34 PM
 * @version v1.0
 */
@RestController
public class StorageFileToDoController {

  private static final Logger LOG = LoggerFactory.getLogger(StorageFileToDoController.class);

  @Autowired
  private StorageFileToDoService storageFileToDoService;

  /**
   * 
   * @author fanyb
   * @Description: 新增
   * @param storageFileToDo 对象
   * @return Map<String,Object>
   * @date Aug 26, 20154:55:45 PM
   *
   * @修改人
   * @修改日期
   */
  @RequestMapping(value = "/token/storage_file_to_do/add", method = RequestMethod.GET)
  public Map<String, Object> add(StorageFileToDo storageFileToDo) {
    LOG.debug("/token/storage_file_to_do/add {}", storageFileToDo);
    Map<String, Object> map = new HashMap<String, Object>();
    map.put("code", Constant.CODE_ERROR);
    boolean addFlag = storageFileToDoService.add(storageFileToDo);
    if (addFlag) {
      map.put("code", Constant.CODE_SUCCESS);
      return map;
    }
    LOG.debug("add {}", map);
    return map;
  }

  /**
   * 
   * 
   * @author fanyb
   * @Description: 查找未处理StorageFileToDo列表
   * @return Map<String,Object>
   * @date Aug 26, 20154:57:06 PM
   *
   * @修改人
   * @修改日期
   */
  @RequestMapping(value = "/token/storage_file_to_do/list/untreated", method = RequestMethod.GET)
  public Map<String, Object> findUntreatedList() {
    LOG.debug("/token/storage_file_to_do/list/untreated {}");
    Map<String, Object> map = new HashMap<String, Object>();
    map.put("code", Constant.CODE_ERROR);
    map.put("list", storageFileToDoService.findUntreatedList());
    map.put("code", Constant.CODE_SUCCESS);
    LOG.debug("findUntreatedList {}");
    return map;
  }

  /**
   * 
   * @author fanyb
   * @Description: 批量删除
   * @param ids 删除id数组
   * @return Map<String,Object>
   * @date Aug 26, 20155:10:37 PM
   *
   * @修改人
   * @修改日期
   */
  @RequestMapping(value = "/token/storage_file_to_do/delete/storage_file_to_do_ids", method = RequestMethod.GET)
  public Map<String, Object> delete(String[] storageFileToDoIds) {
    LOG.debug("/token/storage_file_to_do/delete/storage_file_to_do_ids {}" + storageFileToDoIds);
    Map<String, Object> map = new HashMap<String, Object>();
    map.put("code", Constant.CODE_ERROR);
    boolean deleteFlag = storageFileToDoService.delete(storageFileToDoIds);
    if (deleteFlag) {
      map.put("code", Constant.CODE_SUCCESS);
      return map;
    }
    LOG.debug("delete {}", map);
    return map;
  }

  /**
   * 
   * @author fanyb
   * @Description: 更新
   * @param storageFileTodo
   * @return Map<String,Object>
   * @date Sep 16, 20152:34:14 PM
   *
   * @修改人
   * @修改日期
   */
  @RequestMapping(value = "/token/storage_file_to_do/update", method = RequestMethod.GET)
  public Map<String, Object> update(StorageFileToDo storageFileTodo) {
    LOG.debug("/token/storage_file_to_do/update {}", storageFileTodo);
    Map<String, Object> map = new HashMap<String, Object>();
    map.put("code", Constant.CODE_ERROR);
    boolean updateFlag = storageFileToDoService.update(storageFileTodo);
    if (updateFlag) {
      map.put("code", Constant.CODE_SUCCESS);
      return map;
    }
    LOG.debug("update {}", map);
    return map;
  }

  /**
   * 
   * @author fanyb
   * @Description: 判断storageFileToDo是否存在
   * @param storageCloudId
   * @param datasourceId
   * @param signature
   * @return boolean
   * @date Sep 16, 20155:21:28 PM
   *
   * @修改人
   * @修改日期
   */
  @RequestMapping(value = "/token/storage_file_to_do/is_exist", method = RequestMethod.GET)
  public Map<String, Object> isExistStorageFileToDo(String storageCloudId, String datasourceId,
      String signature) {
    LOG.debug("/token/storage_file_to_do/is_exist {}", storageCloudId, datasourceId, signature);
    Map<String, Object> map = new HashMap<String, Object>();
    map.put("code", Constant.CODE_ERROR);
    boolean existFlag =
        storageFileToDoService.isExistStorageFileToDo(storageCloudId, datasourceId, signature);
    map.put("message", existFlag);
    map.put("code", Constant.CODE_SUCCESS);
    LOG.debug("isExistStorageFileToDo {}", map);
    return map;
  }

  /**
   * 
   * @author fanyb
   * @Description: 根据数据源编号和文件签名查找StorageFileToDo对象
   * @param datasourceId
   * @param signature
   * @return Map<String,Object>
   * @date Sep 17, 20159:15:25 AM
   *
   * @修改人
   * @修改日期
   */
  @RequestMapping(value = "/token/storage_file_to_do/find/datasource_id_signature", method = RequestMethod.GET)
  public Map<String, Object> findByDatasourceIdAndSignature(String datasourceId, String signature) {
    LOG.debug("/token/storage_file_to_do/find/datasource_id_signature {}", datasourceId, signature);
    Map<String, Object> map = new HashMap<String, Object>();
    map.put("code", Constant.CODE_ERROR);
    StorageFileToDo storageFileToDo =
        storageFileToDoService.findByDatasourceIdAndSignature(datasourceId, signature);
    map.put("obj", storageFileToDo);
    map.put("code", Constant.CODE_SUCCESS);
    LOG.debug("findByDatasourceIdAndSignature {}", map);
    return map;
  }
}
